import 'package:flustars/flustars.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:provider/provider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBGongGongCreateTimeModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBWorkTaiNetWork/YBBaseWorkTaiNetWorkManager.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBUtils/YBBaseUtils/YBCallPhoneUtils.dart';

import 'YBMiShuProvider/YBMiShuProvider.dart';
import 'YBMiShuSubPage/YBMiShuTongListDetailSubPage.dart';

//此为已获商机详情页
class YBMiShuYouXuanDetailPage extends StatefulWidget {

  final String sysCode;
  final String requestCode;
  final String feedstatus;
  const YBMiShuYouXuanDetailPage({Key key, this.sysCode, this.requestCode,this.feedstatus}) : super(key: key);

  @override
  _YBMiShuYouXuanDetailPageState createState() => _YBMiShuYouXuanDetailPageState(sysCode: sysCode,requestCode: requestCode,feedstatus: feedstatus);
}

class _YBMiShuYouXuanDetailPageState extends State<YBMiShuYouXuanDetailPage> {

  final String sysCode;
  final String requestCode;
  final String feedstatus;
  _YBMiShuYouXuanDetailPageState({this.sysCode, this.requestCode,this.feedstatus});

  bool _selectXieYi = false;

  @override
  Widget build(BuildContext context) {
    Widget infoWidget;
    Widget yiyiwidget;
    if (int.parse(feedstatus) == 0){
      yiyiwidget = Container(
        child: Row(
          children: [
            Container(
              width: YBTextStyle.adapterSize15,
            ),
            Container(
              child: InkWell(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Container(
                      child: Image.asset(YBImageStyle.getImagePath('mine_mybangzhu'),width:YBTextStyle.adapterSize20,height: YBTextStyle.adapterSize20,),
                    ),
                    Container(
                      child: Text(YBChineseText.workTaiYiYiTitle,style: YBTextStyle.TextStyle7A7A7A011,),
                    ),
                  ],
                ),
                onTap: () async {
                  YBApplication.router.navigateTo(context, '/workTaiPage/workTaiLvSiTongPage/workTaiMiShuYiYiDetailPage/workTaiMiShuYiYiDetailQuestionFeedFeekPage?syscode=$sysCode&&requestCode=$requestCode');
                },
              ),
            ),
          ],
        ),
      );
      infoWidget = Container(
        child: Padding(
          padding: EdgeInsets.only(left:YBTextStyle.adapterSize20),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                child:InkWell(
                  child: _selectXieYi == false?Image.asset(YBImageStyle.getImagePath("login_default")):Image.asset(YBImageStyle.getImagePath("login_selected")),
                  onTap: () async {
                    setState(() {
                      _selectXieYi = !_selectXieYi;
                    });
                  },
                ),
              ),
              Container(
                width: YBTextStyle.adapterSize5,
              ),
              Container(
                child: RichText(
                  text:TextSpan(
                    style: YBTextStyle.homeSmallSubText,
                    children:<InlineSpan>[
                      TextSpan(
                        text: YBChineseText.woYiYueDuBingTongYiTitle,
                        style: YBTextStyle.logincolor383A3D13Light,
                      ),
                      TextSpan(
                          text: YBChineseText.workTaiShangJiKuManangerTitle,
                          style: YBTextStyle.login2D69E013light,
                          recognizer: TapGestureRecognizer()..onTap = (){
                            if (sysCode.contains('xg_newyijiwang')) {
                              YBApplication.router.navigateTo(context,
                                  "/workTaiPage/workTaiMiShuTongPage/workTaiMiShuShangJikuPage/workTaiMiShuShangjikuListDetailPage/workTaiMiShuShangJiManangerIdeaYiJiPage");
                            }else if (sysCode.contains("xg_jinrilvsi")){
                              YBApplication.router.navigateTo(context,
                                  "/workTaiPage/workTaiMiShuTongPage/workTaiMiShuShangJikuPage/workTaiMiShuShangjikuListDetailPage/workTaiMiShuShangJiManangerIdeaLvSiPage");
                            }
                          }
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      );
    }else{
      infoWidget = Container();
      yiyiwidget = Container();
    }

    return Container(
      child: Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Text(
            YBChineseText.workTaiShangJiDetailTitle,
            style: YBTextStyle.TextStyle30313320Medium
          ),
        ),
        body:MultiProvider(
          providers:[
            ChangeNotifierProvider(create:(context)=>YBYIJiTonglvsiTongYouXuanDetailProvider()..getGongGongYouXuanDataList(sysCode, requestCode)),
          ],
          child: Consumer<YBYIJiTonglvsiTongYouXuanDetailProvider>(
             builder:(context,yihuoData,child){
               String createTimeStr;
               if (yihuoData.gongGongYouXuanModel.requestAssignRecordList != null) {
                 YBGongGongCreateTimeModel createTimeModel = yihuoData.gongGongYouXuanModel.requestAssignRecordList.last;
                 createTimeStr = createTimeModel.createTime;
               }
               return Column(
                 mainAxisAlignment: MainAxisAlignment.start,
                 crossAxisAlignment: CrossAxisAlignment.stretch,
                 children: [
                   Expanded(
                     child:CustomScrollView(
                       slivers: <Widget>[
                         SliverToBoxAdapter(
                           child: Container(
                             child: Column(
                               children: [
                                 Container(
                                   color:YBColor.white,
                                   child: Padding(
                                     padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                     child: Column(
                                       children: [
                                         Container(
                                           height: YBTextStyle.adapterSize20,
                                         ),
                                         Container(
                                           child: Row(
                                             mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                             crossAxisAlignment: CrossAxisAlignment.center,
                                             children: [
                                               Container(
                                                 child: Text(
                                                   createTimeStr??"",
                                                   style: YBTextStyle.TextStyle1B1C1F15Medium,
                                                 ),
                                               ),
                                               Container(
                                                 child: Text(
                                                   "${yihuoData.gongGongYouXuanModel.request.provinceName}-${yihuoData.gongGongYouXuanModel.request.cityName}"??"",
                                                   style: YBTextStyle.TextStyle6E737A13,
                                                 ),
                                               ),
                                             ],
                                           ),
                                         ),
                                         Container(
                                           height: YBTextStyle.adapterSize16,
                                         ),
                                         Container(
                                           child: Row(
                                             children: [
                                               Container(
                                                 child: Image.asset(YBImageStyle.getImagePath('BLBBusinessOppoManager_phonr')),
                                               ),
                                               Container(
                                                 width: YBTextStyle.adapterSize5,
                                               ),
                                               Container(
                                                 child: Text(
                                                   yihuoData.gongGongYouXuanModel.linkPhone??'',
                                                   style: YBTextStyle.TextStyle6E737A13,
                                                 ),
                                               ),
                                             ],
                                           ),
                                         ),
                                         Container(
                                           height: YBTextStyle.adapterSize16,
                                         ),
                                       ],
                                     ),
                                   ),
                                 ),
                                 Container(
                                   height: YBTextStyle.adapterSize8,
                                 ),
                                 Container(
                                   color: YBColor.white,
                                   child: Padding(
                                     padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                     child: Column(
                                       mainAxisAlignment: MainAxisAlignment.start,
                                       crossAxisAlignment: CrossAxisAlignment.stretch,
                                       children: [
                                         Container(
                                           child: Text(
                                             "需求内容",
                                             style: YBTextStyle.TextStyle1B1C1F15Medium,
                                           ),
                                         ),
                                         Container(
                                           height: YBTextStyle.adapterSize15,
                                         ),
                                         Container(
                                           child: Text(
                                             yihuoData.gongGongYouXuanModel.request.requestServiceDesc??"",
                                             style: YBTextStyle.TextStyle6E737A13,
                                           ),
                                         ),
                                         Container(
                                           height: YBTextStyle.adapterSize15,
                                         ),
                                       ],
                                     ),
                                   ),
                                 ),
                                 Container(
                                   height: YBTextStyle.adapterSize8,
                                 ),
                               ],
                             ),
                           ),
                         ),
                         SliverToBoxAdapter(
                           child: Container(
                             color:YBColor.white,
                             child: Padding(
                               padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,top: YBTextStyle.adapterSize15),
                               child: Text(
                                 YBChineseText.workTaiMishuDetailliuzhuanJiluTitle,
                                 style: YBTextStyle.TextStyle1B1C1F15Medium,
                               ),
                             ),
                           ),
                         ),
                         SliverList(
                           delegate:SliverChildBuilderDelegate((_,int index){
                             YBGongGongCreateTimeModel createTimeModel = yihuoData.gongGongYouXuanModel.requestAssignRecordList[index];
                             return YBMiShuTongListDetailSubPage(numberStr: (index + 1).toString(),timeStr: createTimeModel.createTime,);
                           },
                               childCount: yihuoData.gongGongYouXuanModel.requestAssignRecordList.length
                           ),
                         ),
                       ],
                     ),
                   ),
                   infoWidget,
                   Container(
                     height: YBTextStyle.adapterSize15,
                   ),
                   Container(
                     height: YBTextStyle.adapterSize44,
                     child: Padding(
                       padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                       child:Row(
                         children: [
                           Container(
                             child: InkWell(
                               child: Column(
                                 mainAxisAlignment: MainAxisAlignment.center,
                                 crossAxisAlignment: CrossAxisAlignment.center,
                                 children: [
                                   Container(
                                     child: Image.asset(YBImageStyle.getImagePath('lawyer_telphone'),width: YBTextStyle.adapterSize20,height: YBTextStyle.adapterSize20,),
                                   ),
                                   Container(
                                     child: Text(YBChineseText.workTaiDianHuaTitle,style: YBTextStyle.TextStyle7A7A7A011,),
                                   ),
                                 ],
                               ),
                               onTap: () async {
                                 YBCallPhoneUtils().getCallPhoneUtils("tel:${yihuoData.gongGongYouXuanModel.linkPhone}"??"");
                               },
                             ),
                           ),
                           yiyiwidget,
                           Container(
                             width: YBTextStyle.adapterSize15,
                           ),
                           Expanded(
                             child: int.parse(feedstatus) == 0?MaterialButton(
                                       shape: RoundedRectangleBorder(
                                         side: BorderSide.none,
                                         borderRadius: BorderRadius.all(Radius.circular(YBTextStyle.adapterSize8)),
                                       ),
                                       color: YBColor.commonThemeColor,
                                       child: Text(YBChineseText.workTaiYouXiaoShangJiTitle,style: YBTextStyle.xieGangQingNianTuiGuangYuanBtnText,),
                                  onPressed:(){
                                       if(_selectXieYi == false){
                                         EasyLoading.showInfo(YBChineseText.qingTongYiXieYiTitle);
                                         return;
                                       }
                                     _youXiaoShangJi(requestCode, sysCode);
                                   }):MaterialButton(
                                     shape: RoundedRectangleBorder(
                                       side: BorderSide.none,
                                       borderRadius: BorderRadius.all(Radius.circular(YBTextStyle.adapterSize8)),
                                     ),
                                     color: YBColor.color7A7A7A,
                                     child: Text(YBChineseText.workTaiYiFanKuiTitle,style: YBTextStyle.xieGangQingNianTuiGuangYuanBtnText,),
                                     onPressed:(){}),
                           ),
                         ],
                       ),
                     ),
                   ),
                   Container(
                     height: YBTextStyle.adapterSize15,
                   ),
                 ],
               );
             }
          ),
        ),
      ),
    );
  }


  void _youXiaoShangJi(String requestCode, String sysCode){
    print('-----$requestCode---$sysCode-');
    YBBaseWorkTaiNetWork.workTaiYiHuoShangJiYouXiao({
      "requestCode":requestCode,
      "sysCode":sysCode,
    },success: (data){
      var dataBool = data;
      if (dataBool is bool){
        EasyLoading.showSuccess("有效商机");
      }
    },fail: (error){
      print('object--$error');
    });
  }
  
}

